package com.mxpio.erp.plan.mrp.bo;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

public class CountModel implements Comparable<CountModel> {

	private String itemCode;
	
	private BigDecimal count;
	
	private Date orderDate;
	
	private Date orderStartDate;
	
	private String remark;
	
	private String boCode;
	
	private String indexes;
	
	//销售订单1 生产订单2 采购订单3 
	private Integer type;
	
	public CountModel(String itemCode, BigDecimal count) {
		super();
		this.itemCode = itemCode;
		this.count = count;
	}

	public CountModel(String itemCode, BigDecimal count, Date orderDate) {
		super();
		this.itemCode = itemCode;
		this.count = count;
		this.orderDate = orderDate;
	}

	public CountModel() {
		super();
	}

	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public BigDecimal getCount() {
		return count;
	}

	public void setCount(BigDecimal count) {
		this.count = count;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Override
	public int compareTo(CountModel o) {

		Calendar thisCal = Calendar.getInstance();
		thisCal.setTime(this.orderDate);
		if(this.type != null && this.type == 1){
			thisCal.set(Calendar.HOUR_OF_DAY, 0);
			thisCal.set(Calendar.MINUTE, 0);
			thisCal.set(Calendar.SECOND, 0);
			thisCal.set(Calendar.MILLISECOND, 30);
		}else{
			thisCal.set(Calendar.HOUR_OF_DAY, 0);
			thisCal.set(Calendar.MINUTE, 0);
			thisCal.set(Calendar.SECOND, 0);
			thisCal.set(Calendar.MILLISECOND, 0);
		}
		Date thisOrderDate =  thisCal.getTime();
		
		Calendar targetCal = Calendar.getInstance();
		targetCal.setTime(o.getOrderDate());
		if(o.getType() != null && o.getType() == 1){
			targetCal.set(Calendar.HOUR_OF_DAY, 0);
			targetCal.set(Calendar.MINUTE, 0);
			targetCal.set(Calendar.SECOND, 0);
			targetCal.set(Calendar.MILLISECOND, 30);
		}else{
			targetCal.set(Calendar.HOUR_OF_DAY, 0);
			targetCal.set(Calendar.MINUTE, 0);
			targetCal.set(Calendar.SECOND, 0);
			targetCal.set(Calendar.MILLISECOND, 0);
		}
		Date targetOrderDate =  targetCal.getTime();
		
		if(thisOrderDate.before(targetOrderDate)){
			return -1;
		}else if(thisOrderDate.equals(targetOrderDate)){
			if(this.type == null || o.getType() == null){
				return 0;
			}
			return o.getType() - this.type;
		}else{
			return 1;
		}
	}

	public String getBoCode() {
		return boCode;
	}

	public void setBoCode(String boCode) {
		this.boCode = boCode;
	}

	public Date getOrderStartDate() {
		return orderStartDate;
	}

	public void setOrderStartDate(Date orderStartDate) {
		this.orderStartDate = orderStartDate;
	}

	public String getIndexes() {
		return indexes;
	}

	public void setIndexes(String indexes) {
		this.indexes = indexes;
	}
	
}
